#ifndef LIBMEMORY_H
#define LIBMEMORY_H
#include <SWAP/StaticMemory.h>
#include <IPC/streamIO.h>
using namespace StaticMemory;

namespace LibMemory
{
  struct _libhead		//-fPic //It's the head of file
  {
    _length size;
    //	unsigned int mark;
    //	unsigned int __bss;
  };
}  
    struct _libs
  {
    _ptlong* functbl;
    _hfptlong functblsize;
    _hfptlong pagenum;
    _length size;
    stminfo* stmhandle;       //size is static
    _mlock  locker;			//protect the lib_state
    _ptlong stat;
    _fstr file;
    _libs* upgrade;
    _ptlong refered;  //facing to muti-thread in one process problem //for IFD using
  };


  _libs* CreateLibMemory(_pcb* pro,_ptlong* vAddr,_hfptlong pagenum,_ptlong flag);
  int ShareLibMemory(_pcb* pro,_ptlong* vAddr,_libs* lib);
  _libs* UpgradeLibMemory(_libs* lib, _libs* upgrade);
  int RemoveLibMemory(_libs* lib,_pcb* pro);
  inline _libs* FileStreamToLibMemory(_fstr stream,_pcb* pro,_ptlong* vAddr,_length num,_length offset);
  _fstr LibMemoryToFileStream(_pcb* pro,_libs* lib);//Use copy-on-write;
  _libs* SetFlagLibMemory(_libs* lib, _ptlong flag);
  _libs* SetFstrLibMemory(_libs* lib,_fstr target);


#endif
